<template>
	<view class="login_view">
		<div class="head-title-cls">
			重庆市党政机关办公用房 督查汇报系统
		</div>
		<div class="f_column_center">
			<image src="/static/login_head.png" style="width: 555rpx" mode="widthFix" />
			<div class="login_bg">
				<div style="padding: 50rpx;">
					<div class="f_row_center">
						<image src="/static/login_u.png" style="width: 32rpx;margin-right: 16rpx" mode="widthFix" />
						<input v-model="user" class="flex_1" placeholder-class="placeholder-style"
							style="padding: 37rpx 0" placeholder="请输入账号" />
					</div>
					<div class="h_line" />
					<div class="f_row_center">
						<image src="/static/login_p.png" style="width: 32rpx;margin-right: 16rpx" mode="widthFix" />
						<input v-model="password" type="password" class="flex_1" placeholder-class="placeholder-style"
							style="padding: 37rpx 0" placeholder="请输入密码" />
					</div>
					<div class="h_line" />
					<button :loading="loading" @click="login" class="button-cls" type="primary">登录</button>
					<div class="hint-cls" style="margin-top: 20px">如忘记密码，请联系管理人员</div>
				</div>
			</div>
		</div>
	</view>
</template>

<script lang="ts">
	import { Vue, Component } from "vue-property-decorator";
	import XRouterConfig from "@/api/XRouterConfig";
	import BaseApi from "@/api/BaseApi";
	import ApiDefine from "@/api/ApiDefine";


	@Component({
		components: {}
	})
	export default class LoginView extends Vue {
		// 基础表单数据
		user = "201@QTSS4200007201";
		password = "bgyf111111";
		loading = false;


		created() {

		}
		async login() {
			if (this.user == '') {
				BaseApi.instance().showToast('请输入账号')
				return;
			}
			if (this.password == '') {
				BaseApi.instance().showToast('请输入密码')
				return;
			}
			this.loading = true;
			//这里appid从原生传过来
			let value = await BaseApi.instance().fetch(ApiDefine.LOGIN_URL, {
				sysuserlogin: this.user,
				password: this.password,
			}, "POST");
			console.log(value, this.user, this.password, '555555555')
			uni.setStorageSync('userId', value.data)
			BaseApi.instance().showToast(value?.msg)
			this.loading = false;
			if (value == null || value.code != 200) {
				return;
			}
			
			let res = await BaseApi.instance().fetch(ApiDefine.ACCOUNT_AUTH, {
				username: this.user,
				data: value.data,
			}, "POST", {
				"content-type": "application/json"
			})
			console.log(value.data,'555555555')
			if (res.code == 200) {
				uni.setStorageSync('x-token', res.result.token)
				let infoRes = await BaseApi.instance().fetch(ApiDefine.baseInfo, {}, "GET", { "Token": res.result.token })
				console.log(infoRes, 'crjreds')
				uni.setStorageSync('regionId', infoRes.result.regionId)
			}
			BaseApi.instance().onLoginOkWidthToken('');
			XRouterConfig.replace('home')
		}
	}
</script>

<style scoped>
	.head-title-cls {
		font-size: 50rpx;
		padding: 132rpx 100rpx 40rpx 100rpx;
		text-align: center;
		font-weight: 600;
		background: linear-gradient(180deg, #FFFFFF 0%, #CFE6FC 100%, #CFE6FC 100%);
		-webkit-background-clip: text;
		-webkit-text-fill-color: transparent;
	}

	.login_view {
		background: url("@/static/bg.png") no-repeat;
		background-size: 100% 100%;
		height: 100vh;
		overflow-y: scroll;
	}

	.login_view>>>.uni-easyinput__content {
		min-height: 100rpx;
		border-color: #FFFFFF;
	}

	.button-cls {
		height: 100rpx;
		background: #3072F6;
		border-radius: 50rpx;
		background: linear-gradient(90deg, #64ACF6 0%, #3F77F4 100%);
		box-shadow: 0px 5rpx 15rpx 0px rgba(65, 122, 244, 0.4);
		font-size: 32rpx;
		line-height: 100rpx;
		margin-top: 46rpx;
		color: #ffffff;
	}

	.hint-cls {
		font-size: 28rpx;
		color: #969696;
		text-align: center;
	}

	.placeholder-style {
		color: #C8C8C8;
		font-size: 32rpx;
	}

	.login_bg {
		background: #FFFFFF;
		box-shadow: 0px 10rpx 30rpx 0px rgba(0, 0, 0, 0.05);
		border-radius: 20rpx;
		width: 690rpx;
		margin-bottom: 64rpx;
	}
</style>